<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"><title>狼族少年、血狼</title><meta name="author" content="狼族少年、血狼"><meta name="copyright" content="狼族少年、血狼"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta property="og:type" content="website">
<meta property="og:title" content="狼族少年、血狼">
<meta property="og:url" content="https://geekwolfman.github.io/page/2/index.html">
<meta property="og:site_name" content="狼族少年、血狼">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://geekwolfman-blog.oss-cn-chengdu.aliyuncs.com/config/avatar/avatar.png">
<meta property="article:author" content="狼族少年、血狼">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://geekwolfman-blog.oss-cn-chengdu.aliyuncs.com/config/avatar/avatar.png"><link rel="shortcut icon" href="https://geekwolfman-blog.oss-cn-chengdu.aliyuncs.com/config/avatar/avatar.png"><link rel="canonical" href="https://geekwolfman.github.io/page/2/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/db.json","preload":false,"languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: true,
  }
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '狼族少年、血狼',
  isPost: false,
  isHome: true,
  isHighlightShrink: false,
  isToc: false,
  postUpdate: '2023-06-08 14:15:24'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      if (id) link.id = id
      link.onerror = reject
      link.onload = link.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        link.onload = link.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.3.0"></head><body><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/pace-js/themes/blue/pace-theme-minimal.min.css"/><script src="https://cdn.jsdelivr.net/npm/pace-js/pace.min.js"></script><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://geekwolfman-blog.oss-cn-chengdu.aliyuncs.com/config/avatar/avatar.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">57</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">14</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">9</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/gallery/"><i class="fa-fw fas fa-images"></i><span> 画廊</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-paper-plane"></i><span> 关于</span></a></div></div></div></div><div class="page" id="body-wrap"><header class="full_page" id="page-header" style="background-image: url('https://geekwolfman-blog.oss-cn-chengdu.aliyuncs.com/config/pages/01index.png')"><nav id="nav"><span id="blog-info"><a href="/" title="狼族少年、血狼"><span class="site-name">狼族少年、血狼</span></a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search" href="javascript:void(0);"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/gallery/"><i class="fa-fw fas fa-images"></i><span> 画廊</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-paper-plane"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="site-info"><h1 id="site-title">狼族少年、血狼</h1><div id="site-subtitle"><span id="subtitle"></span></div></div><div id="scroll-down"><i class="fas fa-angle-down scroll-down-effects"></i></div></header><main class="layout" id="content-inner"><div class="recent-posts" id="recent-posts"><div class="recent-post-item"><div class="post_cover left"><a href="/2023/04/19/%E6%95%B4%E6%95%B0%E6%8B%86%E5%88%86.html" title="整数拆分"><img class="post-bg" src="https://geekwolfman-blog.oss-cn-chengdu.aliyuncs.com/articles/%E6%95%B4%E6%95%B0%E6%8B%86%E5%88%86/00cover.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="整数拆分"></a></div><div class="recent-post-info"><a class="article-title" href="/2023/04/19/%E6%95%B4%E6%95%B0%E6%8B%86%E5%88%86.html" title="整数拆分">整数拆分</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-04-19T15:15:52.000Z" title="发表于 2023-04-19 23:15:52">2023-04-19</time><span class="article-meta-separator">|</span><i class="fas fa-history"></i><span class="article-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-04-19T15:18:23.319Z" title="更新于 2023-04-19 23:18:23">2023-04-19</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/%E7%AE%97%E6%B3%95%E7%BB%83%E4%B9%A0/">算法练习</a></span></div><div class="content">题目描述
题目链接：343. 整数拆分

给定一个正整数 n ，将其拆分为 k 个 正整数 的和（ k &gt;= 2 ），并使这些整数的乘积最大化。
返回 你可以获得的最大乘积 。
示例1：
123输入: n = 2输出: 1解释: 2 = 1 + 1, 1 × 1 = 1。

示例2：
123输入: n = 10输出: 36解释: 10 = 3 + 3 + 4, 3 × 3 × 4 = 36。

提示：

2 &lt;= n &lt;= 58

我的题解方法一：动态规划思路考虑一个整数拆或者不拆，则递推公式为：
1dp[i] = Math.max(dp[i - j] * j, (i - j) * j)

代码123456789101112class Solution &#123;    public int integerBreak(int n) &#123;        int[] dp = new int[n];        dp[0] = 1;        for (int i = 1; i &lt; dp.length; i++) &#123;             ...</div></div></div><div class="recent-post-item"><div class="post_cover right"><a href="/2023/04/19/%E4%B8%8D%E5%90%8C%E8%B7%AF%E5%BE%84-II.html" title="不同路径 II"><img class="post-bg" src="https://geekwolfman-blog.oss-cn-chengdu.aliyuncs.com/articles/%E4%B8%8D%E5%90%8C%E8%B7%AF%E5%BE%84%20II/00cover.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="不同路径 II"></a></div><div class="recent-post-info"><a class="article-title" href="/2023/04/19/%E4%B8%8D%E5%90%8C%E8%B7%AF%E5%BE%84-II.html" title="不同路径 II">不同路径 II</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-04-19T15:11:38.000Z" title="发表于 2023-04-19 23:11:38">2023-04-19</time><span class="article-meta-separator">|</span><i class="fas fa-history"></i><span class="article-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-04-19T15:15:39.673Z" title="更新于 2023-04-19 23:15:39">2023-04-19</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/%E7%AE%97%E6%B3%95%E7%BB%83%E4%B9%A0/">算法练习</a></span></div><div class="content">题目描述
题目链接：63. 不同路径 II

一个机器人位于一个 m x n 网格的左上角 （起始点在下图中标记为 “Start” ）。
机器人每次只能向下或者向右移动一步。机器人试图达到网格的右下角（在下图中标记为 “Finish”）。
现在考虑网格中有障碍物。那么从左上角到右下角将会有多少条不同的路径？
网格中的障碍物和空位置分别用 1 和 0 来表示。
示例1：

123456输入：obstacleGrid = [[0,0,0],[0,1,0],[0,0,0]]输出：2解释：3x3 网格的正中间有一个障碍物。从左上角到右下角一共有 2 条不同的路径：1. 向右 -&gt; 向右 -&gt; 向下 -&gt; 向下2. 向下 -&gt; 向下 -&gt; 向右 -&gt; 向右

示例2：

12输入：obstacleGrid = [[0,1],[0,0]]输出：1

提示：

m == obstacleGrid.length
n == obstacleGrid[i].length
1 &lt;= m, n &lt;= 100
obstacleGrid[i][j] 为 0 或 1
 ...</div></div></div><div class="recent-post-item"><div class="post_cover left"><a href="/2023/04/19/%E4%B8%8D%E5%90%8C%E8%B7%AF%E5%BE%84.html" title="不同路径"><img class="post-bg" src="https://geekwolfman-blog.oss-cn-chengdu.aliyuncs.com/articles/%E4%B8%8D%E5%90%8C%E8%B7%AF%E5%BE%84/00cover.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="不同路径"></a></div><div class="recent-post-info"><a class="article-title" href="/2023/04/19/%E4%B8%8D%E5%90%8C%E8%B7%AF%E5%BE%84.html" title="不同路径">不同路径</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-04-19T15:06:58.000Z" title="发表于 2023-04-19 23:06:58">2023-04-19</time><span class="article-meta-separator">|</span><i class="fas fa-history"></i><span class="article-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-04-19T15:11:19.202Z" title="更新于 2023-04-19 23:11:19">2023-04-19</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/%E7%AE%97%E6%B3%95%E7%BB%83%E4%B9%A0/">算法练习</a></span></div><div class="content">题目描述
题目链接：62. 不同路径

一个机器人位于一个 m x n 网格的左上角 （起始点在下图中标记为 “Start” ）。
机器人每次只能向下或者向右移动一步。机器人试图达到网格的右下角（在下图中标记为 “Finish” ）。
问总共有多少条不同的路径？

12输入：m = 3, n = 7输出：28

示例1：
1234567输入：m = 3, n = 2输出：3解释：从左上角开始，总共有 3 条路径可以到达右下角。1. 向右 -&gt; 向下 -&gt; 向下2. 向下 -&gt; 向下 -&gt; 向右3. 向下 -&gt; 向右 -&gt; 向下

示例2：
12输入：m = 7, n = 3输出：28

示例3：
12输入：m = 3, n = 3输出：6

提示：

1 &lt;= m, n &lt;= 100
题目数据保证答案小于等于 2 * 10(9)

我的题解方法一：动态规划思路假设当前位置为(i, j)，那么有两种路径可以到达当前位置，即(i-1, j)和(i, j-1)，因此到达当前位置的路径数可由左边和上边的路径推出，因此递推公式为：
1dp[i][j ...</div></div></div><div class="recent-post-item"><div class="post_cover right"><a href="/2023/04/19/%E4%BD%BF%E7%94%A8%E6%9C%80%E5%B0%8F%E8%8A%B1%E8%B4%B9%E7%88%AC%E6%A5%BC%E6%A2%AF.html" title="使用最小花费爬楼梯"><img class="post-bg" src="https://geekwolfman-blog.oss-cn-chengdu.aliyuncs.com/articles/%E4%BD%BF%E7%94%A8%E6%9C%80%E5%B0%8F%E8%8A%B1%E8%B4%B9%E7%88%AC%E6%A5%BC%E6%A2%AF/00cover.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="使用最小花费爬楼梯"></a></div><div class="recent-post-info"><a class="article-title" href="/2023/04/19/%E4%BD%BF%E7%94%A8%E6%9C%80%E5%B0%8F%E8%8A%B1%E8%B4%B9%E7%88%AC%E6%A5%BC%E6%A2%AF.html" title="使用最小花费爬楼梯">使用最小花费爬楼梯</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-04-19T09:12:37.000Z" title="发表于 2023-04-19 17:12:37">2023-04-19</time><span class="article-meta-separator">|</span><i class="fas fa-history"></i><span class="article-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-04-19T09:14:06.845Z" title="更新于 2023-04-19 17:14:06">2023-04-19</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/%E7%AE%97%E6%B3%95%E7%BB%83%E4%B9%A0/">算法练习</a></span></div><div class="content">题目描述
题目链接：746. 使用最小花费爬楼梯

给你一个整数数组 cost ，其中 cost[i] 是从楼梯第 i 个台阶向上爬需要支付的费用。一旦你支付此费用，即可选择向上爬一个或者两个台阶。
你可以选择从下标为 0 或下标为 1 的台阶开始爬楼梯。
请你计算并返回达到楼梯顶部的最低花费。
示例1：
12345输入：cost = [10,15,20]输出：15解释：你将从下标为 1 的台阶开始。- 支付 15 ，向上爬两个台阶，到达楼梯顶部。总花费为 15 。

示例2：
12345678910输入：cost = [1,100,1,1,1,100,1,1,100,1]输出：6解释：你将从下标为 0 的台阶开始。- 支付 1 ，向上爬两个台阶，到达下标为 2 的台阶。- 支付 1 ，向上爬两个台阶，到达下标为 4 的台阶。- 支付 1 ，向上爬两个台阶，到达下标为 6 的台阶。- 支付 1 ，向上爬一个台阶，到达下标为 7 的台阶。- 支付 1 ，向上爬两个台阶，到达下标为 9 的台阶。- 支付 1 ，向上爬一个台阶，到达楼梯顶部。总花费为 6 。

提示：

2 &lt;= co ...</div></div></div><div class="recent-post-item"><div class="post_cover left"><a href="/2023/04/19/%E7%88%AC%E6%A5%BC%E6%A2%AF.html" title="爬楼梯"><img class="post-bg" src="https://geekwolfman-blog.oss-cn-chengdu.aliyuncs.com/articles/%E7%88%AC%E6%A5%BC%E6%A2%AF/00cover.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="爬楼梯"></a></div><div class="recent-post-info"><a class="article-title" href="/2023/04/19/%E7%88%AC%E6%A5%BC%E6%A2%AF.html" title="爬楼梯">爬楼梯</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-04-19T09:10:11.000Z" title="发表于 2023-04-19 17:10:11">2023-04-19</time><span class="article-meta-separator">|</span><i class="fas fa-history"></i><span class="article-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-04-19T09:12:03.303Z" title="更新于 2023-04-19 17:12:03">2023-04-19</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/%E7%AE%97%E6%B3%95%E7%BB%83%E4%B9%A0/">算法练习</a></span></div><div class="content">题目描述
题目链接：70. 爬楼梯

假设你正在爬楼梯。需要 n 阶你才能到达楼顶。
每次你可以爬 1 或 2 个台阶。你有多少种不同的方法可以爬到楼顶呢？
示例1：
12345输入：n = 2输出：2解释：有两种方法可以爬到楼顶。1. 1 阶 + 1 阶2. 2 阶

示例2：
123456输入：n = 3输出：3解释：有三种方法可以爬到楼顶。1. 1 阶 + 1 阶 + 1 阶2. 1 阶 + 2 阶3. 2 阶 + 1 阶

提示：

1 &lt;= n &lt;= 45

我的题解方法一：动态规划思路当爬到第n阶楼梯时，有两种方法可以到达：

从n-1阶楼梯爬1阶到第n阶
从n-2阶楼梯爬2阶到第n阶

因此动态规划公式为：dp[n] &#x3D; dp[n-1] + dp[n-2]
因为当前状态只依赖前两个状态，因此，可以使用变量优化
代码1234567891011121314class Solution &#123;    public int climbStairs(int n) &#123;        if (n &lt; 3) &#123;             ...</div></div></div><div class="recent-post-item"><div class="post_cover right"><a href="/2023/04/19/%E6%96%90%E6%B3%A2%E9%82%A3%E5%A5%91%E6%95%B0.html" title="斐波那契数"><img class="post-bg" src="https://geekwolfman-blog.oss-cn-chengdu.aliyuncs.com/articles/%E6%96%90%E6%B3%A2%E9%82%A3%E5%A5%91%E6%95%B0/00cover.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="斐波那契数"></a></div><div class="recent-post-info"><a class="article-title" href="/2023/04/19/%E6%96%90%E6%B3%A2%E9%82%A3%E5%A5%91%E6%95%B0.html" title="斐波那契数">斐波那契数</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-04-19T09:08:00.000Z" title="发表于 2023-04-19 17:08:00">2023-04-19</time><span class="article-meta-separator">|</span><i class="fas fa-history"></i><span class="article-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-04-19T09:09:46.509Z" title="更新于 2023-04-19 17:09:46">2023-04-19</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/%E7%AE%97%E6%B3%95%E7%BB%83%E4%B9%A0/">算法练习</a></span></div><div class="content">题目描述
题目链接：509. 斐波那契数

斐波那契数 （通常用 F(n) 表示）形成的序列称为 斐波那契数列 。该数列由 0 和 1 开始，后面的每一项数字都是前面两项数字的和。也就是：
12F(0) = 0，F(1) = 1F(n) = F(n - 1) + F(n - 2)，其中 n &gt; 1

给定 n ，请计算 F(n) 。
示例1：
123输入：n = 2输出：1解释：F(2) = F(1) + F(0) = 1 + 0 = 1

示例2：
123输入：n = 3输出：2解释：F(3) = F(2) + F(1) = 1 + 1 = 2

示例3：
123输入：n = 4输出：3解释：F(4) = F(3) + F(2) = 2 + 1 = 3

提示：

0 &lt;= n &lt;= 30

我的题解方法一：动态规划思路一个简单的状态转移
代码1234567891011121314class Solution &#123;    public int fib(int n) &#123;        if (n == 0 || n == 1) &#123;      ...</div></div></div><div class="recent-post-item"><div class="post_cover left"><a href="/2023/04/19/%E5%AD%90%E9%9B%86.html" title="子集"><img class="post-bg" src="https://geekwolfman-blog.oss-cn-chengdu.aliyuncs.com/articles/%E5%AD%90%E9%9B%86/00cover.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="子集"></a></div><div class="recent-post-info"><a class="article-title" href="/2023/04/19/%E5%AD%90%E9%9B%86.html" title="子集">子集</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-04-19T08:59:58.000Z" title="发表于 2023-04-19 16:59:58">2023-04-19</time><span class="article-meta-separator">|</span><i class="fas fa-history"></i><span class="article-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-04-19T09:01:46.526Z" title="更新于 2023-04-19 17:01:46">2023-04-19</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/%E7%AE%97%E6%B3%95%E7%BB%83%E4%B9%A0/">算法练习</a></span></div><div class="content">题目描述
题目链接：78. 子集

给你一个整数数组 nums ，数组中的元素 互不相同 。返回该数组所有可能的子集（幂集）。
解集 不能 包含重复的子集。你可以按 任意顺序 返回解集。
示例1：
12输入：nums = [1,2,3]输出：[[],[1],[2],[1,2],[3],[1,3],[2,3],[1,2,3]]

示例2：
12输入：nums = [0]输出：[[],[0]]

提示：

1 &lt;= nums.length &lt;= 10
-10 &lt;= nums[i] &lt;= 10
nums 中的所有元素 互不相同

我的题解方法一：回溯思路当前元素选或者不选
代码123456789101112131415161718192021class Solution &#123;    public List&lt;List&lt;Integer&gt;&gt; subsets(int[] nums) &#123;        List&lt;List&lt;Integer&gt;&gt; result = new ArrayList&lt;&gt;();    ...</div></div></div><div class="recent-post-item"><div class="post_cover right"><a href="/2023/04/19/%E5%AD%97%E7%AC%A6%E4%B8%B2%E7%9B%B8%E4%B9%98.html" title="字符串相乘"><img class="post-bg" src="https://geekwolfman-blog.oss-cn-chengdu.aliyuncs.com/articles/%E5%AD%97%E7%AC%A6%E4%B8%B2%E7%9B%B8%E4%B9%98/00cover.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="字符串相乘"></a></div><div class="recent-post-info"><a class="article-title" href="/2023/04/19/%E5%AD%97%E7%AC%A6%E4%B8%B2%E7%9B%B8%E4%B9%98.html" title="字符串相乘">字符串相乘</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-04-19T08:56:52.000Z" title="发表于 2023-04-19 16:56:52">2023-04-19</time><span class="article-meta-separator">|</span><i class="fas fa-history"></i><span class="article-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-04-19T08:59:11.134Z" title="更新于 2023-04-19 16:59:11">2023-04-19</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/%E7%AE%97%E6%B3%95%E7%BB%83%E4%B9%A0/">算法练习</a></span></div><div class="content">题目描述
题目链接：43. 字符串相乘

给定两个以字符串形式表示的非负整数 num1 和 num2，返回 num1 和 num2 的乘积，它们的乘积也表示为字符串形式。
注意：不能使用任何内置的 BigInteger 库或直接将输入转换为整数。
示例1：
12输入: num1 = &quot;2&quot;, num2 = &quot;3&quot;输出: &quot;6&quot;

示例2：
12输入: num1 = &quot;123&quot;, num2 = &quot;456&quot;输出: &quot;56088&quot;

提示：

1 &lt;&#x3D; num1.length, num2.length &lt;&#x3D; 200
num1 和 num2 只能由数字组成。
num1 和 num2 都不包含任何前导零，除了数字0本身。

我的题解方法一：模拟乘法思路模拟乘法计算过程，使用数组记录中间值。
代码1234567891011121314151617181920212223242526272829class Solution &#123;    pub ...</div></div></div><div class="recent-post-item"><div class="post_cover left"><a href="/2023/04/19/%E6%8B%AC%E5%8F%B7%E7%94%9F%E6%88%90.html" title="括号生成"><img class="post-bg" src="https://geekwolfman-blog.oss-cn-chengdu.aliyuncs.com/articles/%E6%8B%AC%E5%8F%B7%E7%94%9F%E6%88%90/00cover.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="括号生成"></a></div><div class="recent-post-info"><a class="article-title" href="/2023/04/19/%E6%8B%AC%E5%8F%B7%E7%94%9F%E6%88%90.html" title="括号生成">括号生成</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-04-19T08:54:49.000Z" title="发表于 2023-04-19 16:54:49">2023-04-19</time><span class="article-meta-separator">|</span><i class="fas fa-history"></i><span class="article-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-04-19T08:56:24.685Z" title="更新于 2023-04-19 16:56:24">2023-04-19</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/%E7%AE%97%E6%B3%95%E7%BB%83%E4%B9%A0/">算法练习</a></span></div><div class="content">题目描述
题目链接：22. 括号生成

数字 n 代表生成括号的对数，请你设计一个函数，用于能够生成所有可能的并且 有效的 括号组合。
示例1：
12输入：n = 3输出：[&quot;((()))&quot;,&quot;(()())&quot;,&quot;(())()&quot;,&quot;()(())&quot;,&quot;()()()&quot;]

示例2：
12输入：n = 1输出：[&quot;()&quot;]

提示：

1 &lt;= n &lt;= 8

我的题解方法一：回溯+剪枝思路回溯法枚举所有情况，其中根据条件进行剪枝：当已加入的右括号大于左括号，这时不能够构成一个有效的括号
代码12345678910111213141516171819202122232425262728class Solution &#123;    public List&lt;String&gt; generateParenthesis(int n) &#123;        List&lt;String&gt; result = new ArrayList&lt;&gt;( ...</div></div></div><div class="recent-post-item"><div class="post_cover right"><a href="/2023/04/19/%E6%BB%91%E5%8A%A8%E7%AA%97%E5%8F%A3%E6%9C%80%E5%A4%A7%E5%80%BC.html" title="滑动窗口最大值"><img class="post-bg" src="https://geekwolfman-blog.oss-cn-chengdu.aliyuncs.com/articles/%E6%BB%91%E5%8A%A8%E7%AA%97%E5%8F%A3%E6%9C%80%E5%A4%A7%E5%80%BC/00cover.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="滑动窗口最大值"></a></div><div class="recent-post-info"><a class="article-title" href="/2023/04/19/%E6%BB%91%E5%8A%A8%E7%AA%97%E5%8F%A3%E6%9C%80%E5%A4%A7%E5%80%BC.html" title="滑动窗口最大值">滑动窗口最大值</a><div class="article-meta-wrap"><span class="post-meta-date"><i class="far fa-calendar-alt"></i><span class="article-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-04-19T08:52:00.000Z" title="发表于 2023-04-19 16:52:00">2023-04-19</time><span class="article-meta-separator">|</span><i class="fas fa-history"></i><span class="article-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-04-19T08:54:17.877Z" title="更新于 2023-04-19 16:54:17">2023-04-19</time></span><span class="article-meta"><span class="article-meta-separator">|</span><i class="fas fa-inbox"></i><a class="article-meta__categories" href="/categories/%E7%AE%97%E6%B3%95%E7%BB%83%E4%B9%A0/">算法练习</a></span></div><div class="content">题目描述
题目链接：239. 滑动窗口最大值

给你一个整数数组 nums，有一个大小为 k 的滑动窗口从数组的最左侧移动到数组的最右侧。你只可以看到在滑动窗口内的 k 个数字。滑动窗口每次只向右移动一位。
返回 滑动窗口中的最大值 。
示例1：
1234567891011输入：nums = [1,3,-1,-3,5,3,6,7], k = 3输出：[3,3,5,5,6,7]解释：滑动窗口的位置                最大值---------------               -----[1  3  -1] -3  5  3  6  7       3 1 [3  -1  -3] 5  3  6  7       3 1  3 [-1  -3  5] 3  6  7       5 1  3  -1 [-3  5  3] 6  7       5 1  3  -1  -3 [5  3  6] 7       6 1  3  -1  -3  5 [3  6  7]      7

示例2：
12输入：nums = [1], k = 1输出：[1]

提示：

1 &lt;= ...</div></div></div><nav id="pagination"><div class="pagination"><a class="extend prev" rel="prev" href="/"><i class="fas fa-chevron-left fa-fw"></i></a><a class="page-number" href="/">1</a><span class="page-number current">2</span><a class="page-number" href="/page/3/#content-inner">3</a><span class="space">&hellip;</span><a class="page-number" href="/page/6/#content-inner">6</a><a class="extend next" rel="next" href="/page/3/#content-inner"><i class="fas fa-chevron-right fa-fw"></i></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://geekwolfman-blog.oss-cn-chengdu.aliyuncs.com/config/avatar/avatar.png" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">狼族少年、血狼</div><div class="author-info__description"></div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">57</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">14</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">9</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://wpa.qq.com/msgrd?v=3&amp;uin=2370032534&amp;site=qq&amp;menu=yes&amp;jumpflag=1"><i class="fa-brands fa-qq"></i><span>添加博主QQ</span></a></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">本站所有博文均是博主的学习笔记与个人理解，来源于网络，如有<span style="color:red;font-weight:bold;">侵权</span>请<a target="_blank" rel="noopener" href="https://wpa.qq.com/msgrd?v=3&uin=2370032534&site=qq&menu=yes&jumpflag=1" style="color:#49B1F5;font-weight:bold">联系我</a>进行删除🥰。</div></div><div class="sticky_layout"><div class="card-widget card-webinfo"><div class="item-headline"><i class="fas fa-chart-line"></i><span>网站资讯</span></div><div class="webinfo"><div class="webinfo-item"><div class="item-name">文章数目 :</div><div class="item-count">57</div></div><div class="webinfo-item"><div class="item-name">已运行时间 :</div><div class="item-count" id="runtimeshow" data-publishDate="2023-03-21T16:00:00.000Z"><i class="fa-solid fa-spinner fa-spin"></i></div></div><div class="webinfo-item"><div class="item-name">本站总字数 :</div><div class="item-count">173k</div></div><div class="webinfo-item"><div class="item-name">本站访客数 :</div><div class="item-count" id="busuanzi_value_site_uv"><i class="fa-solid fa-spinner fa-spin"></i></div></div><div class="webinfo-item"><div class="item-name">本站总访问量 :</div><div class="item-count" id="busuanzi_value_site_pv"><i class="fa-solid fa-spinner fa-spin"></i></div></div><div class="webinfo-item"><div class="item-name">最后更新时间 :</div><div class="item-count" id="last-push-date" data-lastPushDate="2023-06-08T06:15:23.179Z"><i class="fa-solid fa-spinner fa-spin"></i></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2023 By 狼族少年、血狼</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><div class="js-pjax"><script>window.typedJSFn = {
  init: (str) => {
    window.typed = new Typed('#subtitle', Object.assign({
      strings: str,
      startDelay: 300,
      typeSpeed: 150,
      loop: true,
      backSpeed: 50,
    }, null))
  },
  run: (subtitleType) => {
    if (true) {
      if (typeof Typed === 'function') {
        subtitleType()
      } else {
        getScript('https://cdn.jsdelivr.net/npm/typed.js/lib/typed.min.js').then(subtitleType)
      }
    } else {
      subtitleType()
    }
  }
}
</script><script>function subtitleType () {
  fetch('https://v1.hitokoto.cn')
    .then(response => response.json())
    .then(data => {
      if (true) {
        const from = '出自 ' + data.from
        const sub = []
        sub.unshift(data.hitokoto, from)
        typedJSFn.init(sub)
      } else {
        document.getElementById('subtitle').innerHTML = data.hitokoto
      }
    })
}
typedJSFn.run(subtitleType)
</script></div><script defer="defer" id="ribbon" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/canvas-ribbon.min.js" size="150" alpha="0.6" zIndex="-1" mobile="false" data-click="false"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div><script src="/js/search/local-search.js"></script></div></body></html>